<?php


namespace App\Services;


class SmsServices
{
    protected $statusStr;
    protected $smsapi;
    protected $user;
    protected $pass;


    public function __construct()
    {
        $this->statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );

        $this->smsapi = "http://api.smsbao.com/";
        $this->user = "jerorry";
        $this->pass = md5('801218');
    }

    public function sendSms($mobile, $content = '')
    {
        $capatch = rand(1000, 9999);
        $content = "您的验证码是：" . $capatch;
        $sendUrl = $this->smsapi."sms?u=".$this->user."&p=".$this->pass."&m=".$mobile."&c=".urlencode($content);
        $result = file_get_contents($sendUrl);

        return ['code' => $this->statusStr[$result], 'capatch' => $capatch];
    }
}
